feat: Add session variable support for all execution modes#58
Merged
Conversation
Extends PostgreSQL session variable setting (app.tenant_id, app.contact_id) to all FraiseQL execution modes (normal, passthrough, turbo) to enable consistent multi-tenant database access patterns. Changes: - Add _set_session_variables helper method to FraiseQLRepository - Integrate session variable setting in all database execution paths - Support both psycopg (cursor) and asyncpg (connection) interfaces - Add comprehensive test coverage for session variables across modes This enables Row-Level Security (RLS) and multi-tenant patterns to work consistently regardless of the execution mode, addressing the issue where queries would fail when falling back from TurboRouter to normal mode. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends PostgreSQL session variable setting (
app.tenant_id,app.contact_id) to all FraiseQL execution modes to enable consistent multi-tenant database access patterns.Problem
Previously, session variables were only set in TurboRouter mode. When queries fell back to normal or passthrough modes, the session variables were not set, causing queries that rely on Row-Level Security (RLS) to fail.
This addresses the feature request documented in
/tmp/fraiseql_session_variables_feature_request.mdfrom the PrintOptim Backend Team.Solution
_set_session_variableshelper method to FraiseQLRepositoryChanges
_set_session_variablesmethod and integrated it into all query execution pathsTest Plan
✅ Added comprehensive test suite:
✅ All existing tests pass:
Impact
This enables Row-Level Security (RLS) and multi-tenant patterns to work consistently regardless of execution mode, fixing issues where queries would fail when falling back from TurboRouter to normal mode.
Before
After
Implementation Details
The implementation uses TDD methodology:
🤖 Generated with Claude Code